package com.xr.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.xr.constant.MessageConstant;
import com.xr.pojo.SetMeal;
import com.xr.result.Result;
import com.xr.service.SetMealService;
import com.xr.utils.QiNiuUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/*
* 移动端套餐Controller
* */

@RestController
@RequestMapping("setMealMobile")
public class SetMealMobileController {

    @Reference
    private SetMealService setMealService;

//    查询所有套餐
    @RequestMapping("/queryAllMobile")
    public Result queryAllMobile(){
        try {
            List<SetMeal> setMeals = setMealService.queryAll();
            for (SetMeal setmeals : setMeals){
                setmeals.setImg(QiNiuUtils.DOMAIN+setmeals.getImg());
                System.out.println("img:"+setmeals.getImg());
            }
            return  new Result(true, MessageConstant.QUERY_SETMEAL_SUCCESS,setMeals);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,MessageConstant.QUERY_SETMEALLIST_FAIL);
        }
    }
    //根据套餐id查询检查组和检查项info
    @RequestMapping("/findById")
    public Result findById(Integer id){
        try {
            SetMeal setMeal = setMealService.queryGroupAndItemBySetMealId(id);
            setMeal.setImg(QiNiuUtils.DOMAIN+setMeal.getImg());
            return new Result(true,MessageConstant.QUERY_SETMEAL_SUCCESS,setMeal);
        }catch (Exception e){
            e.printStackTrace();
            return  new Result(false,MessageConstant.QUERY_SETMEALLIST_FAIL);
        }
    }
}
